﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Configuration;
using System.Net;
using System.IO;
namespace ProcessesSMS
{
    /// <summary>
    /// Summary description for CKVN.
    /// </summary>
    public class VUONTAOXANH
    {

        private SMS_MO WMO;
        private SMS_MT WMT;
        //private SMS_LIST WML;
        ArrayList arr = new ArrayList();
        public VUONTAOXANH(SMS_MO MO)
        {
            WMO = MO;
        }

        public VUONTAOXANH()
        {
        }
        public void run()
        {
            WMT = new SMS_MT(WMO);
            string tmpMsg = WMO.Message.Substring(WMO.CommandCode.Length).Trim().Replace("  ", " ").Replace("  ", " ");
            tmpMsg = tmpMsg.Replace("  ", " ").Trim().ToUpper();
            string[] msg = tmpMsg.Split(new char[] { ' ' });
            //if (strReturnMsg != "")
            //{
            string[] strReturnMsg = GetReturnMsg(msg).Split('|');
            for (int i = 0; i < strReturnMsg.Length; i++)
            {
                WMT.AddMessage(WMO.UserID, strReturnMsg[i], SMS_ContentType.SMS_TEXT);
                WMT.MsgType = SMS_MsgType.SMS_TINHTIEN;
            }
            WMT.Insert();
            //}
            return;
        }
        private string GetReturnMsg(string[] arr)
        {
            string msgBody = string.Empty;            
            if (((WMO.ServiceID.Replace("04", "") == "6072") || (WMO.ServiceID.Replace("04", "") == "6172") || (WMO.ServiceID.Replace("04", "") == "6272")) && (WMO.UserID !="84902222776"))
            {
                msgBody = "Dich vu binh chon y tuong Kinh Te Xanh chi ap dung cho dau so 6372!";
            }
            else
            {
                if (arr.Length >= 2)
                {
                    vuontaoxanh.ServiceSMS ws = new ProcessesSMS.vuontaoxanh.ServiceSMS();
                    msgBody = ws.ReturnResult(arr[0], arr[1]);
                }
                else
                {
                    msgBody = "Cu phap khong dung.De binh chon y tuong Kinh Te Xanh, soan tin: KTX <MaSoBinhChon> <SoNguoiBinhChon> gui den 6372";
                }
            }
            return msgBody;
        }
    }
}
